// McCursor.h: interface for the McCursor class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MCCURSOR_H__95F91744_1341_47CD_9C15_039DD45F3065__INCLUDED_)
#define AFX_MCCURSOR_H__95F91744_1341_47CD_9C15_039DD45F3065__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "my_node.h"

template<class T>
class McCursorVectorT : public McCursorBase
{
	bool bFirstTime_;
	const vector<T> items_;
	vector<T>::const_iterator itEnd_;
protected:
	virtual bool next(void)
	{
		if(!bFirstTime_)
		{
			bFirstTime_ = true;
			it_ = items_.begin();
			itEnd_ = items_.end();
		}
		else
			it_++;
		return it_ != itEnd_;
	}
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor)
	{
		pCursor = NULL;
		return false;
	}
	virtual bool get_cond(const string& cond_name, bool& bTrue)
	{
		if(cond_name == "is_first")
		{
			bTrue = it_ == items_.begin();
			return true;
		}
		else if(cond_name == "have_element")
		{
			bTrue = !items_.empty();
			return true;
		}
		else if(cond_name == "is_last")
		{
			vector<T>::const_iterator it(it_);
			it++;
			bTrue = it == items_.end();
			return true;
		}
		return false;
	}
	virtual bool get_var(const string& var_name, string& var_value)
	{
		var_value.erase();
		return false;
	}
protected:
	vector<T>::const_iterator it_;
	long item_offset(void)
	{
		return it_ - items_.begin();
	}
public:
	McCursorVectorT(const vector<T>& items)
		:items_(items), bFirstTime_(false)
	{
	}
};

template<class T>
class McCursorSingleT : public McCursorBase
{
	bool bFirstTime_;
	virtual bool next(void)
	{
		if(!bFirstTime_)
		{
			bFirstTime_ = true;
			return true;
		}
		return false;
	}
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor)
	{
		pCursor = NULL;
		return false;
	}
	virtual bool get_cond(const string& cond_name, bool& bTrue)
	{
		bTrue = false;
		return false;
	}
	virtual bool get_var(const string& var_name, string& var_value)
	{
		var_value.erase();
		return false;
	}
protected:
	const T& item_;
public:
	McCursorSingleT(const T& item)
		:item_(item), bFirstTime_(false)
	{
	}
};

class McCursorComments : public McCursorVectorT<string>
{
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorComments(const vector<string>& items);
};
class McCursorIdl : public McCursorSingleT<MsIdlDefine>
{
	const string& base_name_;
	long lngPktypeLow_;
	long lngPktypeHigh_;
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorIdl(const MsIdlDefine& item, const string& base_name, long lngPktypeLow, long lngPktypeHigh);
};

class McCursorEnums : public McCursorVectorT<MsEnumDefine>
{
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorEnums(const vector<MsEnumDefine>& items);
};
class McCursorEnumMembers : public McCursorVectorT<MsEnumMember>
{
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorEnumMembers(const vector<MsEnumMember>& items);
};

class McCursorStructs : public McCursorVectorT<MsStructDefine>
{
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
	virtual bool get_cond(const string& cond_name, bool& bTrue);
public:
	McCursorStructs(const vector<MsStructDefine>& items);
};
class McCursorStructMembers : public McCursorVectorT<MsStructMember>
{
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorStructMembers(const vector<MsStructMember>& items);
};

struct MsDefaultValue
{
	string member_name;
	string default_value;
};
class McCursorStructDefaultMembers : public McCursorVectorT<MsDefaultValue>
{
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorStructDefaultMembers(const vector<MsDefaultValue>& items);
};
class McCursorExceptionDefines : public McCursorVectorT<MsExceptionDefine>
{
	long pkTypeBase_;
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
	virtual bool get_cond(const string& cond_name, bool& bTrue);
public:
	McCursorExceptionDefines(const vector<MsExceptionDefine>& items, long pkTypeBase);
};


class McCursorMethods : public McCursorVectorT<MsMethodDefine>
{
	const vector<MsExceptionDefine>& exceptionDefs_;
	long pkTypeBase_;
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_cond(const string& cond_name, bool& bTrue);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorMethods(const vector<MsMethodDefine>& items, long pkTypeBase, const vector<MsExceptionDefine>& exceptionDefs);
};

class McCursorArgs : public McCursorVectorT<MsArg>
{
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorArgs(const vector<MsArg>& items);
};

class McCursorExceptions : public McCursorVectorT<MsException>
{
	const vector<MsExceptionDefine>& exceptionDefs_;
	virtual bool get_cursor(const string& cont_name, McCursorBase*& pCursor);
	virtual bool get_var(const string& var_name, string& var_value);
public:
	McCursorExceptions(const vector<MsException>& items, const vector<MsExceptionDefine>& exceptionDefs);
};


#endif // !defined(AFX_MCCURSOR_H__95F91744_1341_47CD_9C15_039DD45F3065__INCLUDED_)
